const express = require('express');

const app = express();

app.get('/user', (req, res) => {
  console.log(req.query);
  res.send({ id: 1, name: 'zs1' });
});

// 根据 id 获取该用户的详细信息
app.get('/user/id/:id/name/:name', (req, res) => {
  console.log(req.params, 'req.params');

  const { id } = req.params;

  console.log(id, typeof id, 'id');

  // db.getData();
  // 假设这个数组是 数据库里的数据
  var allUsers = [
    { id: 1, name: 'zs' },
    { id: 2, name: 'ls' },
    { id: 3, name: 'ww' },
  ];
  const user = allUsers.find((v) => v.id === parseInt(id));

  res.send(user);
});

app.post('/user', (req, res) => {
  res.send('ok');
});

app.listen(80, () => {
  console.log(' ok....');
});
